package com.lm.iotdb.controller;

import com.lm.iotdb.entry.DeviceDataDTO;
import com.lm.iotdb.service.IoTDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/iot")
public class IoTController {

    @Autowired
    private IoTDataService service;

    @PostMapping("/upload")
    public ResponseEntity<String> upload(@RequestBody DeviceDataDTO dto) {
        boolean inserted = service.save(dto);
        return inserted ?
                ResponseEntity.ok("上传成功") :
                ResponseEntity.status(HttpStatus.CONFLICT).body("重复数据，已跳过");
    }
}